package memory_read

import (
	"OrdDeFi-Virtual-Machine/db_utils"
	"OrdDeFi-Virtual-Machine/safe_number"
	"OrdDeFi-Virtual-Machine/virtual_machine/memory/memory_const"
	"errors"
)

/*
Across all versions.
*/

func ODFIMeta() *memory_const.CoinMeta {
	result := new(memory_const.CoinMeta)
	result.Max = safe_number.SafeNumFromString("21000000")
	result.Lim = safe_number.SafeNumFromString("1000")
	result.AddrLim = safe_number.SafeNumFromString("1000")
	result.Desc = "The protocol major coin of OrdDeFi."
	result.Icon = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgZmlsbD0ibm9uZSI+PGcgY2xpcC1wYXRoPSJ1cmwoI2EpIj48cGF0aCBmaWxsPSIjMTgxQjFFIiBkPSJNMCAwaDQ4djQ4SDBWMFoiLz48cGF0aCBmaWxsPSIjRkVGRUZFIiBkPSJNMTMuODQzIDEyaDUuODcxdjMuNDI5aC01LjE0M3Y3Ljg1MWwtLjg1Ny42di45NDNsLjg1Ny41NTd2Ny4xOTFoNS4xNDNWMzZoLTUuODcxbC0yLjctMy40Mjl2LTYuODU3SDguNTd2LTMuNDI4aDIuNTcydi02Ljg1N2wyLjctMy40MjlabTIwLjMxNCAwaC01Ljg3MXYzLjQyOWg1LjE0M3Y3Ljg1MWwuODU3LjZ2Ljk0M2wtLjg1Ny41NTd2Ny4xOTFoLTUuMTQzVjM2aDUuODcxbDIuNy0zLjQyOXYtNi44NTdoMi41NzJ2LTMuNDI4aC0yLjU3MnYtNi44NTdMMzQuMTU3IDEyWiIvPjxtYXNrIGlkPSJiIiB3aWR0aD0iMTAiIGhlaWdodD0iMTgiIHg9IjE4LjcxNCIgeT0iMTYuMjg2IiBmaWxsPSIjMDAwIiBtYXNrVW5pdHM9InVzZXJTcGFjZU9uVXNlIj48cGF0aCBmaWxsPSIjZmZmIiBkPSJNMTguNzE0IDE2LjI4NmgxMHYxOGgtMTB6Ii8+P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ljc2OC0yLjE5bC0uMzY0LS4zNjNjLS42MzEuNjMyLS45MTkgMS41MDMtLjkxOSAyLjU1M2guNTE0Wm0uNzc1LTIuMTk3Yy40ODEtLjUyMSAxLjIyLS43ODMgMi4yMjgtLjc4M3YtLjUxNWMtMS4wOSAwLTEuOTkzLjI4NS0yLjYwNi45NWwuMzc4LjM0OFoiIG1hc2s9InVybCgjYikiLz48L2c+PGRlZnM+PGNsaXBQYXRoIGlkPSJhIj48cGF0aCBmaWxsPSIjZmZmIiBkPSJNMCAwaDQ4djQ4SDB6Ii8+PC9jbGlwUGF0aD48L2RlZnM+PC9zdmc+"
	return result
}

func ODGVMeta() *memory_const.CoinMeta {
	result := new(memory_const.CoinMeta)
	result.Max = safe_number.SafeNumFromString("21000000")
	result.Lim = safe_number.SafeNumFromString("1000")
	result.AddrLim = safe_number.SafeNumFromString("1000")
	result.Desc = "The governance coin of OrdDeFi."
	result.Icon = "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0OCIgaGVpZ2h0PSI0OCIgZmlsbD0ibm9uZSI+PGcgY2xpcC1wYXRoPSJ1cmwoI2EpIj48cGF0aCBmaWxsPSIjMTgxQjFFIiBkPSJNMCAwaDQ4djQ4SDBWMFoiLz48cGF0aCBmaWxsPSIjRkVGRUZFIiBkPSJNMTMuODQzIDEyaDUuODcxdjMuNDI5aC01LjE0M3Y3Ljg1MWwtLjg1Ny42di45NDNsLjg1Ny41NTd2Ny4xOTFoNS4xNDNWMzZoLTUuODcxbC0yLjctMy40Mjl2LTYuODU3SDguNTd2LTMuNDI4aDIuNTcydi02Ljg1N2wyLjctMy40MjlabTIwLjMxNCAwaC01Ljg3MXYzLjQyOWg1LjE0M3Y3Ljg1MWwuODU3LjZ2Ljk0M2wtLjg1Ny41NTd2Ny4xOTFoLTUuMTQzVjM2aDUuODcxbDIuNy0zLjQyOXYtNi44NTdoMi41NzJ2LTMuNDI4aC0yLjU3MnYtNi44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xLjE3OC0uOTA3LTIuMDE5LS45MDd2LjUxNWMuNzA4IDAgMS4yNDEuMjQzIDEuNjE3LjcxM2wuNDAyLS4zMjFaIiBtYXNrPSJ1cmwoI2IpIi8+PC9nPjxkZWZzPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTAgMGg0OHY0OEgweiIvPjwvY2xpcFBhdGg+PC9kZWZzPjwvc3ZnPg=="
	return result
}

/*
CoinMeta read coin metadata from db
*/
func CoinMeta(db *db_utils.OrdDB, coinName string) (*memory_const.CoinMeta, error) {
	if coinName == "" {
		return nil, errors.New("read CoinMeta error: coin name is empty")
	} else if coinName == "odfi" {
		return ODFIMeta(), nil
	} else if coinName == "odgv" {
		return ODGVMeta(), nil
	}
	key := memory_const.CoinMetadataTable + ":" + coinName
	value, err := db.Read(key)
	if err != nil {
		if err.Error() == "leveldb: not found" {
			return nil, nil
		} else {
			return nil, err
		}
	}
	if value == nil {
		return nil, errors.New("read CoinMeta error: coin not found in db")
	}
	coinMeta, err := memory_const.CoinMetaFromJsonString(*value)
	if err != nil {
		return nil, err
	}
	return coinMeta, nil
}
